import Vue from 'vue';
import App from './App.vue';
import './directive/directive.js';
import './assets/css/variable.less';

if (process.env.NODE_ENV === 'development') {
    // mock
    console.log('Mock 已加载');
    import('./mock');
}

// babel-polyfill
import 'babel-polyfill';

// router
import router from './router';

// store
import store from './store';

// active方法
import active from './utils/active';

// lang
import i18n from './lang';

// elementUi
import ElementUI, { Message } from 'element-ui';

// elementUiCss
import 'element-ui/lib/theme-chalk/index.css';

// 自定义组件
import '@/components/index';

// 全局过滤器
import '@/utils/filter';

import showCountDown from '@/components/countDown';

import './assets/css/rtl.less';

Vue.use(showCountDown);

// 全局方法
import * as commonUtils from '@/utils/common';
Vue.prototype.$checkStr = commonUtils.checkStr;
Vue.prototype.$nameCheck = commonUtils.nameCheck;

// use active
Vue.use(active);

// 挂载全局loading
import { showLoading, hideLoading } from '@/utils/loading';
Vue.prototype.showLoading = showLoading;
Vue.prototype.hideLoading = hideLoading;

// 阻止 vue 在启动时生成生产提示
Vue.config.productionTip = false;

Vue.prototype.msgsuccess = function (msg) {
    this.$message({
        showClose: true,
        message: msg,
        type: 'success'
    });
};

Vue.prototype.msgerror = function (msg) {
    this.$message({
        showClose: true,
        message: msg,
        type: 'error'
    });
};

Vue.prototype.msginfo = function (msg) {
    this.$message.info(msg);
};

// elementUi message offset
const offset = 0;

//定义一个新的Message方法，多传入一个offset参数
const $message = (options) => {
    return Message({
        ...options,
        offset: offset
    });
};

//重写方法,将offset写入options
['success', 'warning', 'info', 'error'].forEach((type) => {
    $message[type] = (options) => {
        if (typeof options === 'string') {
            options = {
                message: options,
                offset: offset
            };
            // 默认配置
            options.duration = 950;
            options.showClose = true;
        }
        options.type = type;
        return Message(options);
    };
});

//设置ElementUI组件的默认大小
Vue.use(ElementUI, {
    size: 'medium'
});

//全局修改弹窗黑幕点击关闭弹窗默认组件的配置
ElementUI.Dialog.props.appendToBody.default = true;
// 修改 el-dialog 默认点击遮照为不关闭
ElementUI.Dialog.props.closeOnClickModal.default = false;
// 全局修改默认配置，按下ESC不能关闭弹窗
ElementUI.Dialog.props.closeOnPressEscape.default = false;
//将$message挂载到this上
Vue.prototype.$message = $message;
//不加这行代码运行this.$message.closeAll时会报错
Vue.prototype.$message.closeAll = Message.closeAll;

new Vue({
    router,
    store,
    i18n,
    render: (h) => h(App)
}).$mount('#app');


